home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Dragonsmith 1.1.1 / Base files / Utilities / EventUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-15  |  1.8 KB  |  62 lines  |  [TEXT/KAHL]

  1. /*
  2.     EventUtils.c
  3.     
  4.     Event-related utility functions
  5.     
  6.     Created:    15 Jul 1992    YieldCPUTime
  7.     Modified:    03 Sep 1992    Added IsCancelEvent
  8.             
  9.     Copyright © 1992 by Paul M. Hoffman
  10.     Send comments or suggestions to paul.hoffman@umich.edu -or- dragonsmith@umich.edu
  11.     
  12.     This source code may be freely used, altered, and distributed in any way as long as:
  13.         1.    It is GIVEN away rather than sold (except as expressly permitted by the author)
  14.         2.    This statement and the above copyright notice are left intact.
  15.  
  16. */
  17.  
  18. #include    "EventUtils.h"
  19. #include    <Script.h>
  20.  
  21. void YieldCPUTime (unsigned short ticks)
  22. {
  23.     EventRecord    event;
  24.     register long    ticksEnd;
  25.     
  26.     ticksEnd = TickCount () + ticks;
  27.     
  28.     do
  29.         (void) EventAvail (everyEvent, &event);
  30.     while (TickCount () < ticksEnd);
  31.             
  32. }
  33.  
  34. Boolean IsCancelEvent (EventRecord *theEvent)
  35. {
  36.     // Adapted from Tech Note 263 “International Canceling” and Inside Macintosh Vol. IV, page 14–106
  37.     
  38. #define    kMaskModifiers    0xFE00        // Mask out the command key
  39. #define    kMaskVirtualKey    0x0000FF00    // Mask for the virtual key
  40. #define    kMaskASCII1        0x00FF0000    // Get the key out of the ASCII1 byte
  41. #define    kMaskASCII2        0x000000FF    // Get the key out of the ASCII2 byte
  42. #define    cPERIOD            '.'
  43.  
  44.     Ptr            kchrPtr;
  45.     short        keyCode;
  46.     long            virtualKey, keyInfo, lowChar, highChar, deadState;
  47.     
  48.     if (theEvent->modifiers & cmdKey) {
  49.         virtualKey = (theEvent->message & kMaskVirtualKey) >> 8;
  50.         keyCode = (theEvent->modifiers & kMaskModifiers) | virtualKey;
  51.         // Get a pointer to the current 'KCHR' — this will work only in System 7.0 or above
  52.         kchrPtr = (Ptr) GetEnvirons (smKCHRCache);
  53.         deadState = 0;
  54.         keyInfo = KeyTrans (kchrPtr, keyCode, &deadState);
  55.         lowChar = keyInfo & kMaskASCII2;
  56.         highChar = (keyInfo & kMaskASCII1) >> 16;
  57.         return lowChar == cPERIOD || highChar == cPERIOD;
  58.     } else
  59.         return FALSE;
  60. }
  61.  
  62.